package com.nuanshui.framework.lang;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;


public class MoneyUtil {
	
	
	public static Long toLong(Double money) {
		
		NumberFormat nf = new DecimalFormat("#.##");
		Double d = Double.valueOf(nf.format(money))*100;
		long moneyInt = d.intValue();
		return moneyInt;
		
	}
	
	public static double toDouble(Long money) {
		
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return Double.valueOf(nf.format(temp));
		
	}
	
     public static String toDoubleString(Long money) {
		if(money == null)  return "0.00";
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return nf.format(temp);
		
	}
     
     public static String toDoubleString(Integer money) {
 		if(money == null)  return "0.00";
 		double temp  = money/100.0;
 		NumberFormat nf = new DecimalFormat("############0.00");
 		return nf.format(temp);
 		
 	}
     
     /**
      * 元转化为分
      * @param @return
      * @author guohao
      * @date 2016年4月7日 下午1:39:11
      * @since $
      */
     public static long toPenny(Double money) {
    	 if(money == null) return 0;
    	 BigDecimal bigDecimal = BigDecimal.valueOf(money);
 		 bigDecimal = bigDecimal.multiply(BigDecimal.valueOf(100));
    	 return bigDecimal.longValue();
     }
	

	public static String toString(Long money) {
		
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return nf.format(temp);
		
	}
	
	public static void main(String[] args) {
		//System.out.println(toLong(2.333333));
		System.out.println(toDouble(5000l));
	}

}
